home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-23 | 5.5 KB | 209 lines | [TEXT/CWIE] |
- // ===========================================================================
- // UVisualEffect.cp © 1995, Éric Forget. All rights reserved.
- // ===========================================================================
- //
- // ************************************************************************
- // * *
- // * Before using this code you should read the "License Agreement" *
- // * document and agree with it. *
- // * *
- // ************************************************************************
- //
- // UVisualEffect help you doing the "visual effect" like in the Finder
- // when you open or close a file/folder.
- //
- // ---------------------------------------------------------------------------
- // Instructions Notes:
- // ------------------
- //
- // There is two methods:
- //
- // 1) (a) Call one of the two SetFirstXXX() method
- // (b) Call one of the two SetLastXXX() method
- // (c) Call DoPlayEffects()
- // Note that XXX should not necessary be the same for both (a) and (b)
- //
- // 2) (a) Call either SetRects() or SetPanes()
- // (b) Call DoPlayEffects()
- //
- // ---------------------------------------------------------------------------
-
-
- #include "UVisualEffect.h"
-
-
-
-
- // ---------------------------------------------------------------------------
- // • Constantes
- // ---------------------------------------------------------------------------
-
- const Rect Rect_Undefined = { -1, -1, -1, -1 };
-
-
- // ---------------------------------------------------------------------------
- // • Initialisation
- // ---------------------------------------------------------------------------
-
- Int16 UVisualEffect::sNbrStep = 4;
- Rect UVisualEffect::sFirstRect = Rect_Undefined;
- Rect UVisualEffect::sLastRect = Rect_Undefined;
-
-
- // ---------------------------------------------------------------------------
- // • Initialize
- // ---------------------------------------------------------------------------
-
- void
- UVisualEffect::Initialize(
- Int16 inNbrStep)
- {
- sNbrStep = inNbrStep;
- sFirstRect = Rect_Undefined;
- sLastRect = Rect_Undefined;
- }
-
-
- // ---------------------------------------------------------------------------
- // • SetFirstRect
- // ---------------------------------------------------------------------------
-
- void
- UVisualEffect::SetFirstRect(
- Rect inFirstRect)
- {
- sFirstRect = inFirstRect;
- }
-
-
- // ---------------------------------------------------------------------------
- // • SetFirstPane
- // ---------------------------------------------------------------------------
-
- void
- UVisualEffect::SetFirstPane(
- LPane *inFirstPane)
- {
- SetFirstRect(CalcGlobalPaneFrame(inFirstPane));
- }
-
-
- // ---------------------------------------------------------------------------
- // • SetLastRect
- // ---------------------------------------------------------------------------
-
- void
- UVisualEffect::SetLastRect(
- Rect inLastRect)
- {
- sLastRect = inLastRect;
- }
-
-
- // ---------------------------------------------------------------------------
- // • SetLastPane
- // ---------------------------------------------------------------------------
-
- void
- UVisualEffect::SetLastPane(
- LPane *inLastPane)
- {
- SetLastRect(CalcGlobalPaneFrame(inLastPane));
- }
-
-
- // ---------------------------------------------------------------------------
- // • SetRects
- // ---------------------------------------------------------------------------
-
- void
- UVisualEffect::SetRects(
- Rect inFirstRect,
- Rect inLastRect)
- {
- SetFirstRect(inFirstRect);
- SetLastRect(inLastRect);
- }
-
-
- // ---------------------------------------------------------------------------
- // • SetPanes
- // ---------------------------------------------------------------------------
-
- void
- UVisualEffect::SetPanes(
- LPane *inFirstPane,
- LPane *inLastPane)
- {
- SetFirstPane(inFirstPane);
- SetLastPane(inLastPane);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CalcGlobalPaneFrame
- // ---------------------------------------------------------------------------
-
- Rect
- UVisualEffect::CalcGlobalPaneFrame(
- LPane *inPane)
- {
- Rect frame;
-
-
- inPane->CalcPortFrameRect(frame);
-
- inPane->PortToGlobalPoint(topLeft(frame));
- inPane->PortToGlobalPoint(botRight(frame));
-
- return frame;
- }
-
-
- // ---------------------------------------------------------------------------
- // • DoPlayEffects
- // ---------------------------------------------------------------------------
-
- void
- UVisualEffect::DoPlayEffects()
- {
- if (!::EqualRect(&sFirstRect, &Rect_Undefined) &&
- !::EqualRect(&sLastRect, &Rect_Undefined)) {
-
- GrafPtr theScreen = UScreenPort::GetScreenPort();
- Int32 finalTick;
- Rect stepRect, tempRect;
-
-
- LView::OutOfFocus(nil);
- SetPort(theScreen);
-
- stepRect.top = (sLastRect.top - sFirstRect.top ) / (sNbrStep + 2);
- stepRect.left = (sLastRect.left - sFirstRect.left ) / (sNbrStep + 2);
- stepRect.bottom = (sLastRect.bottom - sFirstRect.bottom) / (sNbrStep + 2);
- stepRect.right = (sLastRect.right - sFirstRect.right ) / (sNbrStep + 2);
-
-
- ::PenPat(&UQDGlobals::GetQDGlobals()->gray);
- ::PenMode (patXor);
-
- for(Int16 j = 0; j < 2; j++) {
-
- tempRect = sFirstRect;
-
- for(Int16 i = 0; i < (sNbrStep + 2); i++) {
-
- ::FrameRect(&tempRect);
- ::Delay(1, &finalTick);
- tempRect.top += stepRect.top;
- tempRect.left += stepRect.left;
- tempRect.bottom += stepRect.bottom;
- tempRect.right += stepRect.right;
- }
- ::Delay(4, &finalTick);
- }
- }
-
- // Reset initial value
- Initialize();
- }